package com.neishenmo.sochatapp.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.neishenmo.sochatapp.R;
import com.neishenmo.sochatapp.network.ApiConstract;
import com.neishenmo.sochatapp.network.ApiPresenter;
import com.neishenmo.sochatapp.util.Utils;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;


/**
 * 小果冻
 * 短信验证码验证
 * Created by Administrator on 2018\4\24 0024.
 */

public class VerificationActivity extends AppCompatActivity implements ApiConstract.view{


    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.edit_iphone)
    EditText editIphone;
    private int msgType=0;
    private ApiPresenter apiPresenter=new ApiPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verification);
        ButterKnife.bind(this);
        if (getIntent().getIntExtra("msgType",0)==1){
            msgType=1;
        } else {
            msgType=0;
        }

    }



    @OnClick({R.id.img_back, R.id.img_next, R.id.txt_fasong})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                break;
            case R.id.img_next:
                if (msgType==1) {
                    initHttpUserLogin(getIntent().getStringExtra("iphone"));
                } else {

                }
                break;
            case R.id.txt_fasong:
                break;
        }
    }
    /**
     * 用户登录*/
    private void initHttpUserLogin(String iphone){
        Map<String, String> map = new HashMap<>();
        map.put("telephone", iphone);
        map.put("msgCode", editIphone.getText().toString());

        MediaType JSON = MediaType.parse("application/json; charset=UTF-8");
        RequestBody requestBody = RequestBody.create(JSON, Utils.mapToJson(map));
        apiPresenter.loadUserLogin(requestBody);
    }

    @Override
    public void showErrMsg(String msg) {

    }

    @Override
    public void showInfo(String string) {

    }
}
